<template>
  <div>
  <el-table :data="users.slice((queryPage.currentPage-1)*queryPage.pageSize,queryPage.currentPage*queryPage.pageSize)">
    <el-table-column type="index" label="序号" width="80"></el-table-column>
    <el-table-column prop="username" label="用户名" width="100"> </el-table-column>
    <el-table-column prop="password" label="密码" width="320"> </el-table-column>
    <el-table-column prop="rname" label="身份" width="120"> </el-table-column>
    <el-table-column prop="mobile" label="电话号码" width="120"> </el-table-column>
    <el-table-column prop="email" label="电子邮件" width="120"> </el-table-column>
    <el-table-column label="操作">
      <template slot-scope="scope">
        <el-button size="mini" @click="edit(scope.row.id)">编辑</el-button>
        <el-button
          size="mini"
          type="danger"
          @click="remove(scope.row.id)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
 
  <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="queryPage.currentPage"
      :page-sizes="[1, 2, 5, 10]"
      :page-size="queryPage.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="queryPage.totalPage">
  </el-pagination>
  </div>
</template>

<script>
export default {
  name: "userList",
  data() {
    return {
      queryPage:{
        currentPage: 1,
        totalPage:1000,
        pageSize:1  //每页显示多少条数据
      },
      users: [],
    };
  },
  methods: {
    handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
        this.queryPage.pageSize=val;
      },
      handleCurrentChange(val) {
        console.log(`当前页: ${val}`);
        this.queryPage.currentPage=val
      },
    fetch() {
      this.$http.get("userList").then(res => {
        this.users = res.data;
        this.queryPage.totalPage=this.users.length;
      });
      
    },
    remove(id){
        this.$http.delete(`userList/${id}`).then(res=>{
            console.log(res);
            this.$message({
                message:'删除成功！',
                type:'success'
            })
            this.fetch()
        })

    },
    edit(id){
        this.$router.push(`/main/${id}/editUsers`);
    }
  },
  created() {
    this.fetch();
  },
};
</script>

<style>
</style>